﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FastReport;
using FastReport.Preview;
using MINERP.BLL.Statistics;
using MINERP.MODEL.FoundationModel;

namespace MINERP.Statistics.Forms
{
    public partial class FrmNewOutReturnQuery : Form
    {
        private static FrmNewOutReturnQuery _instance = null;

        OutRetunrOrderRecordsBLL _bll = new OutRetunrOrderRecordsBLL();
        private Report report = new Report();
        private FrmNewOutReturnQuery()
        {
            InitializeComponent();
        }
        public static FrmNewOutReturnQuery Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new FrmNewOutReturnQuery();
                }
                return _instance;
            }
        }

        private void FrmNewOutReturnQuery_Load(object sender, EventArgs e)
        {
            LinkSalesman();
        }

        private void simpleButtonOk_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(cmbSalesman.Text.Trim()))
            {
                DataSet ds = _bll.GetOutReturnInfo(cmbSalesman.Text.Trim(), dtStart.DateTime, dtEnd.DateTime);
                ds.WriteXml(@"C:\WINDOWS\xmlData\SalesmanOutReturnOrder.xml", XmlWriteMode.WriteSchema);
                report.Load(Application.StartupPath + "\\Report\\OutReturnOrderInfo.frx");
                report.Preview = previewControl1;
                previewControl1.Refresh();
                previewControl1.Show();
                report.Show();
            }
            else
            {
                MessageBox.Show("请选择业务员!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }

        public void LinkSalesman()
        {
            List<string> salesmanNameList = _bll.GetSalesmanList();
            cmbSalesman.Properties.Items.Clear();
            foreach (var item in salesmanNameList)
            {
                cmbSalesman.Properties.Items.Add(item);
            }
        }
        private void FrmNewOutReturnQuery_FormClosing(object sender, FormClosingEventArgs e)
        {
            _instance = null;
        }
    }
}
